/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.db;

import org.hibernate.HibernateException;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author Rómulo Galindo Tanta
 */
public class MillionDB {

    private static final SessionFactory sessionFactory;

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    static {
        try {
            sessionFactory = new AnnotationConfiguration().configure("pe/db/hibernate.cfg.xml").buildSessionFactory();
        } catch (HibernateException ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static StatelessSession  new_session(){
        return getSessionFactory().openStatelessSession();
    }
}